<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/5/22 0022
 * Time: 下午 4:28
 */
namespace app\model;
use app\index\controller\BaseCompanyUser;

class CompanyInvite extends \think\Model{
    public $table="company_invite";

    /**
     * 向指定的用户发送面试邀请
     * @param $data
     * @return mixed
     */
    function add_invite($data){
        $data['status']=0;
        $data['created_at']=cur_time();



        $user_job_send_id=$data['user_job_send_id'];
        $UserJobSend=new UserJobSend();
        $ujs_arr=$UserJobSend->get_info_by_id($user_job_send_id);

        $data['company_job_name']=$ujs_arr['job_name'];
        $data['company_name']=$ujs_arr['company_name'];
        return $this->insert($data,false,true);
    }

    /**
     * 根据用户ID,状态 ，返回他的接受邀请公司面试记录
     * @param $user_id
     * @param $status
     * @return mixed
     */
    function get_company_invite_by_user_id($user_id,$status=0){
        $o=$this->where(['user_id'=>$user_id,'status'=>$status])->select();
        $arrs=object2array($o);
        foreach($arrs as $k=>$v){
            $arrs[$k]['status_name']=config('web.company_invite_status')[$v['status']];
        }
        return $arrs;
    }

    /**
     * 公司邀请状态 变成已接受
     * @param $id
     * @return $this
     */
    function change_to_accept_status($id){
       return  $this->where(['id'=>$id])->update(['status'=>3,'updated_at'=>cur_time()]);
    }

    /**
     * 公司邀请状态变成已拒绝
     */
    function change_to_reject_status($id){
        return  $this->where(['id'=>$id])->update(['status'=>2,'updated_at'=>cur_time()]);
    }
}